﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.ComputationUnitVMs
{
    public partial class ComputationUnitListVM : BasePagedListVM<ComputationUnit_View, ComputationUnitSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ComputationUnit_View>> InitGridHeader()
        {
            return new List<GridColumn<ComputationUnit_View>>{
                
                this.MakeGridHeader(x => x.ComputationUnit_UnitCode).SetTitle(@Localizer["Page.单位编码"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_UnitName).SetTitle(@Localizer["Page.单位名称"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ComputationUnit_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ComputationUnit_View> GetSearchQuery()
        {
            var query = DC.Set<ComputationUnit>()
                
                .CheckContain(Searcher.UnitCode, x=>x.UnitCode)
                .CheckContain(Searcher.UnitName, x=>x.UnitName)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ComputationUnit_View
                {
				    ID = x.ID,
                    
                    ComputationUnit_UnitCode = x.UnitCode,
                    ComputationUnit_UnitName = x.UnitName,
                    ComputationUnit_CreateTime = x.CreateTime,
                    ComputationUnit_UpdateTime = x.UpdateTime,
                    ComputationUnit_CreateBy = x.CreateBy,
                    ComputationUnit_UpdateBy = x.UpdateBy,
                    ComputationUnit_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ComputationUnit_View: ComputationUnit
    {
        
        public string ComputationUnit_UnitCode { get; set; }
        public string ComputationUnit_UnitName { get; set; }
        public DateTime? ComputationUnit_CreateTime { get; set; }
        public DateTime? ComputationUnit_UpdateTime { get; set; }
        public string ComputationUnit_CreateBy { get; set; }
        public string ComputationUnit_UpdateBy { get; set; }
        public bool ComputationUnit_IsValid { get; set; }

    }

}